import tkinter as tk
import threading
import time

class SimpleWindow:
    def __init__(self):
        self.root = None
        self.label = None

    def create_window(self):
        """在子线程中创建 GUI"""
        self.root = tk.Tk()
        self.root.title("我的面板")
        self.root.geometry("300x150")

        self.label = tk.Label(self.root, text="等待点击...", font=("微软雅黑", 12))
        self.label.pack(pady=20)

        self.button = tk.Button(self.root, text="点我", command=self.on_button_click)
        self.button.pack()

        # 启动 GUI 主循环（这会阻塞当前线程）
        self.root.mainloop()

    def on_button_click(self):
        print("GUI: 按钮被点击了！")
        if self.label:
            self.label.config(text="已点击！")

    def start(self):
        """启动 GUI 线程"""
        thread = threading.Thread(target=self.create_window, daemon=True)
        thread.start()